package com.my.stock.core;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;

import org.zeromq.ZMQ;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import WebSocket.Handler;
import WebSocket.Websocket;
import util.JavaFile;

public class OptionArbitrage {

	private static Map<String, Date> tradingMap = new HashMap<String, Date>();

	private static boolean started = false;

	private static Set<String> orderStatusSet = new HashSet<String>();

	private static Set<String> filterProduct = new HashSet<String>();

	private static Set<String> sfilterProduct = new HashSet<String>();

	static {
		sfilterProduct.add("eb");
		sfilterProduct.add("bu");
		sfilterProduct.add("ag");
		sfilterProduct.add("jd");
		sfilterProduct.add("pg");
		sfilterProduct.add("IM");
		sfilterProduct.add("bu");
	}

	private static void filterProductOnRelation(String p) {

		Set<String> resultSet = new HashSet<String>();
		for (String[] cs : relationProductList) {
			boolean flag = false;

			for (String product : cs) {

				if (product.equals(p)) {
					flag = true;
				}

			}

			if (flag) {
				for (String product : cs) {
					System.out.println("过滤" + product);

					resultSet.add(product);
				}
			}

		}
		resultSet.remove(p);
		filterProduct.addAll(resultSet);

	}

	private static void rfilterProductOnRelation(String p) {

		Set<String> resultSet = new HashSet<String>();
		for (String[] cs : relationProductList) {
			boolean flag = false;

			for (String product : cs) {

				if (product.equals(p)) {
					flag = true;
				}

			}

			if (flag) {
				for (String product : cs) {
					System.out.println("过滤" + product);

					resultSet.add(product);
				}
			}

		}
		resultSet.remove(p);
		filterProduct.removeAll(resultSet);

	}

	public Thread tickThread = new Thread(new Runnable() {

		public void run() {
			ZMQ.Context context = ZMQ.context(1);
			ZMQ.Socket s = context.socket(ZMQ.PULL);
			s.bind("tcp://127.0.0.1:5556");
			// s.subscribe("".getBytes());
			while (true) {
				byte recStr[] = s.recv();
				String sg = "";
				try {
					if (recStr != null) {
						sg = new String(recStr, "gb2312");
					}
					if (sg.startsWith("ZC")) {
						continue;
					}
					if (sg.startsWith("au")) {
						continue;
					}
//					System.out.println(sg);
					if (sg.startsWith("errorOrder")) {

						System.out.println("下单错误！！！" + sg);

					} else if (sg.startsWith("queryPostion")) {
						if (sg.contains("OPL")) {
							continue;
						}
						if (sg.split(",")[1].length() > 9) {
							continue;
						}

						if (started == false) {

							System.out.println(sg);
							String code = sg.split(",")[1];
							if (Integer.parseInt(sg.split(",")[3]) == 0) {
								continue;
							}
							String tradingOption = "";

//							System.out.println(sg);
							if (code.length() > 9) {

								if (code.startsWith("PX")) {
									code = code.replaceAll("PX", "GXGX");
								}

								if (code.startsWith("PK")) {
									code = code.replaceAll("PK", "KXKX");
								}

								if (code.indexOf("C") > 3) {
									code = code.split("C")[0].replaceAll("-", "");
								}
								if (code.indexOf("P") > 3) {
									code = code.split("P")[0].replaceAll("-", "");
								}

								code = code.replaceAll("GXGX", "PX");
								code = code.replaceAll("KXKX", "PK");
								tradingOption = sg.split(",")[1];
							}

							Product p = productMap.get(code);
							if (p == null) {
								continue;
							}

							if (tradingOption.length() > 0) {
								p.setTradingProduct(tradingOption);
								optionSellPriceMap.put(tradingOption, -1.0);
							} else {
								p.setTradingProduct(code);
							}

							if (Integer.parseInt(sg.split(",")[3]) - Integer.parseInt(sg.split(",")[2]) > 0) {
								p.setTodayTrading(1);
								System.out.print("今日");
							}
							p.setOwnPosition(p.getOwnPosition() + Integer.parseInt(sg.split(",")[3]));
							p.setOrderPrice(Double.parseDouble(sg.split(",")[4]) / Integer.parseInt(sg.split(",")[3])
									/ p.getUnit());

							p.setTradeType(sg.split(",")[5]);
							totalPostionProduct.add(p);
							ownProductMap.put(code, p);

							System.out.println(code + "目前持仓" + p.getTradingProduct() + " 方向" + p.getTradeType() + " 数量"
									+ p.getOwnPosition());

							filterProductOnRelation(p.getContractName());

						}

					} else if (sg.startsWith("OKOrder")) {

//						System.out.println(sg);
						// 订单提交成功
						if (sg.split(",")[3].equals("3") || sg.split(",")[3].equals("0")) {
							// 撤单成功
							if (sg.split(",")[4].equals("5")) {
								String code = sg.split(",")[1];
								Product p = productMap.get(code);
								if (isOption(code)) {
									String future = optionToFuture(code);
									p = productMap.get(future);

								}
								if (sg.split(",")[8].equals("0")) {
									p.setPoolInsertOrderNum(
											p.getPoolInsertOrderNum() - Integer.parseInt(sg.split(",")[11]));
								} else {
									p.setPoolStopOrderNum(
											p.getPoolStopOrderNum() - Integer.parseInt(sg.split(",")[11]));
								}

//								System.out.println("撤单成功！！！" + sg);
							} else if (sg.split(",")[4].equals("0") || sg.split(",")[4].equals("1")
									|| sg.split(",")[4].equals("2")) {

								if (orderStatusSet.contains(
										sg.split(",")[6] + " " + sg.split(",")[2] + " " + sg.split(",")[14])) {
									// 重复订单不处理

								} else {
									orderStatusSet
											.add(sg.split(",")[6] + " " + sg.split(",")[2] + " " + sg.split(",")[14]);
									// 成交
									String code = sg.split(",")[1];
									Product p = productMap.get(code);

									if (sg.split(",")[8].equals("0")) {
										if (isOption(code)) {
											String future = optionToFuture(code);
											p = productMap.get(future);
											p.setTradeType("2");
										} else {
											if (sg.split(",")[13].equals("0")) {
												p.setTradeType("2");
											} else {
												p.setTradeType("3");
											}

										}
										p.setTradingProduct(code);
										// 开仓
										if (sg.split(",")[4].equals("0")) {
											p.setOwnPosition(p.getMaxOrderNum());
										} else {
											p.setOwnPosition(p.getOwnPosition() + Integer.parseInt(sg.split(",")[2]));
										}

										p.setTodayTrading(1);
										p.setPoolInsertOrderNum(
												p.getPoolInsertOrderNum() - Integer.parseInt(sg.split(",")[2]));
										totalPostionProduct.add(p);
										ownProductMap.put(code, p);
										System.out.println(
												"目前持仓" + code + " 方向" + p.getTradeType() + " " + p.getOwnPosition());
										filterProductOnRelation(p.getContractName());

									} else {
										System.out.println(code + "平仓成功" + Integer.parseInt(sg.split(",")[2]) + "手");
										if (isOption(code)) {
											String future = optionToFuture(code);
											p = productMap.get(future);

										}
										if (sg.split(",")[4].equals("0")) {
											p.setOwnPosition(0);
										} else {
											p.setOwnPosition(Integer.parseInt(sg.split(",")[2]));
										}

										p.setPoolStopOrderNum(
												p.getPoolStopOrderNum() - Integer.parseInt(sg.split(",")[2]));
										p.setCloseOrderTime(System.currentTimeMillis());
										// 平仓
										totalPostionProduct.remove(p);
										System.out.println("目前持仓" + code + " " + p.getOwnPosition());
										rfilterProductOnRelation(p.getContractName());

									}
//									System.out.println("订单成交！！！" + sg);
								}

							} else if (sg.split(",")[4].equals("3")) {

//								System.out.println(sg);

							}
						}

					} else {

						processPrice(sg);
						final String tick = sg;
						new Thread(new Runnable() {

							@Override
							public void run() {
								processTrade(tick);

							}

						}).start();

					}

				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
			}
		}

	});

	private static Set<Product> totalPostionProduct = new HashSet<Product>();

	private static boolean isOption(String code) {

		boolean r = false;
		if (code.substring(2, code.length()).indexOf("C") >= 0) {
			r = true;
		}
		if (code.substring(2, code.length()).indexOf("P") >= 0) {
			r = true;
		}

		return r;
	}

	private static String optionToFuture(String code) {

		String f = code.substring(2, code.length());

		String future = "";

		if (f.indexOf("P") >= 0) {
			future = code.substring(0, 2) + f.split("P")[0].replaceAll("-", "").replaceAll(" ", "");
		}
		if (f.indexOf("C") >= 0) {
			future = code.substring(0, 2) + f.split("C")[0].replaceAll("-", "").replaceAll(" ", "");
		}
		return future;
	}

	public void processPrice(String tick) {

		String data[] = tick.split(",");
		String code = data[0];
		double buyPrice = Double.parseDouble(data[3]);
		double sellPrice = Double.parseDouble(data[2]);
		if (buyPrice == 0 || sellPrice == 0) {
			return;
		}
		String updatetime = data[6];
		code = code.replaceAll("-", "");
		if (code.length() >= 9) {
			optionBuyPriceMap.put(code, buyPrice);
			optionSellPriceMap.put(code, sellPrice);
		} else {
			productBuyPriceMap.put(code, buyPrice);
			productSellPriceMap.put(code, sellPrice);
		}
		updateTimeMap.put(code, updatetime);

	}

	public void processTrade(String tick) {
//		System.out.println(tick);
		String data[] = tick.split(",");
		String code = data[0];
		double lastPrice = Double.parseDouble(data[1]);
		double buyPrice = Double.parseDouble(data[3]);
		double sellPrice = Double.parseDouble(data[2]);
		if (buyPrice == 0 || sellPrice == 0) {
			return;
		}
		String updatetime = data[6];

//		System.out.println(updatetime);
		if (code.length() >= 9) {
			code = code.replaceAll("-", "");
			String productName;
			if (code.indexOf("P") == code.lastIndexOf("P") && code.indexOf("P") >= 5) {
				productName = code.split("P")[0];
			} else if (code.indexOf("C") == code.lastIndexOf("C") && code.indexOf("C") >= 5) {
				productName = code.split("C")[0];
			} else {
				return;
			}
			// 期权

			String optionPrice = code.replaceAll(productName, "");

			String optionWay = optionPrice.substring(0, 1);

			String optionP = optionPrice.substring(1, optionPrice.length());

			// System.out.print(productName + " " + productBuyPriceMap.get(productName) + "
			// " + productSellPriceMap.get(productName) + " ");

			// System.out.print(code + " " + buyPrice + " " + sellPrice + " ");
			String name;

			if (optionWay.equals("P")) {
				name = productName + "C" + optionP;
			} else {
				name = productName + "P" + optionP;
			}
			// System.out.print(name + " " + optionBuyPriceMap.get(name) + " " +
			// optionSellPriceMap.get(name) + " ");

			if (optionBuyPriceMap.get(name) != null && productBuyPriceMap.get(productName) != null) {
				boolean dateBeforeBoolean = false;
				try {
					dateBeforeBoolean = DateUtil.parseDate(name)
							.before(new Date(System.currentTimeMillis() - 3600 * 1000));
				} catch (ParseException e) {
					e.printStackTrace();
				}
				if (optionWay.equals("P")) {
					double p = Double.parseDouble(optionP) - (sellPrice - optionBuyPriceMap.get(name));
//					 System.out.print(" optionSellPrice:" + p + " sellPrice:" +  productBuyPriceMap.get(productName));
					double arbitrage = (p - productSellPriceMap.get(productName));
					if (arbitrage > 0) {

						String co = productName.replaceAll("\\d", "");

						if (minStepMap.get(co) == null) {
							System.out.println(co);
						}

						if (arbitrage > minStepMap.get(co) * 4 && dateBeforeBoolean) {

							System.out.print(updateTimeMap.get(name) + " " + updateTimeMap.get(productName) + " "
									+ updatetime + " ");

							System.out.println(code + " arbitrage:" + arbitrage);
						}

					}

				} else {
					double p = Double.parseDouble(optionP) + (sellPrice - optionBuyPriceMap.get(name));
					// System.out.print(" optionBuyPrice:" + p + " buyPrice:" +
					// productSellPriceMap.get(productName));
					double arbitrage = (productBuyPriceMap.get(productName) - p);
					if (arbitrage > 0) {
						String co = productName.replaceAll("\\d", "");
						if (minStepMap.get(co) == null) {
							System.out.println(co);
						}
						if (arbitrage > minStepMap.get(co) * 4 && dateBeforeBoolean) {

							System.out.print(updateTimeMap.get(name) + " " + updateTimeMap.get(productName) + " "
									+ updatetime + " ");

							System.out.println(code + " arbitrage:" + arbitrage);
						}

					}
				}

			}

		}

	}

	private void insertOrder(String trading, double price, String direct, int num, int todayTrading) {
		String order = direct + "," + trading + "," + num + "," + price + "," + todayTrading + "\0";
		if ((direct.equals("buy") || direct.equals("sell"))) {
			if (totalPostionProduct.size() <= 50) {
				signalQueue.offer(order);
			} else {
				System.out.println("已达到最大持仓数量");
			}
		} else {
			signalQueue.offer(order);
		}

//		order = "sell," + code + "," + p.getMaxOrderNum() + "," + (buyPrice - p.getMinStep() * p.getStopLossStep())
//				+ "," + (sellPrice + p.getMinStep() * step) + "\0";
//		signalQueue.offer(order);

	}

	private static Map<String, Product> productMap = new HashMap<String, Product>();

	private static Map<String, Product> ownProductMap = new HashMap<String, Product>();

	public static BlockingQueue<String> signalQueue = new ArrayBlockingQueue<String>(1024);

	Thread tradeThread = new Thread(new Runnable() {
		public void run() {
			ZMQ.Context context = ZMQ.context(1);
			ZMQ.Socket s = context.socket(ZMQ.PUB);
			s.bind("tcp://*:5557");
			while (true) {
				String trade;
				try {
					trade = signalQueue.take();
					System.out.println(trade);
					s.send(trade.getBytes(), 0);

				} catch (InterruptedException e) {
					e.printStackTrace();
				}

			}
		}
	});

	private static Map<String, Double> productBuyPriceMap = new ConcurrentHashMap<String, Double>();
	private static Map<String, Double> productSellPriceMap = new ConcurrentHashMap<String, Double>();
	private static Map<String, Double> optionBuyPriceMap = new ConcurrentHashMap<String, Double>();
	private static Map<String, Double> optionSellPriceMap = new ConcurrentHashMap<String, Double>();

	private static Map<String, String> updateTimeMap = new HashMap<String, String>();

	public static void main(String[] args) throws IOException, InterruptedException {
		List<String> config = JavaFile.readfile("d:\\show1.txt");
		for (String c : config) {
			Product p = new Product();
			p.setHighestPrice(Double.parseDouble(c.split(",")[4]));
			p.setLowestPrice(Double.parseDouble(c.split(",")[5]));
			p.setAtr(Double.parseDouble(c.split(",")[6]));

			p.setCode(c.split(",")[0]);
			p.setContractName(c.split(",")[1]);

			productMap.put(c.split(",")[0], p);
		}

		config = JavaFile.readfile("d:\\show2.txt");
		for (String c : config) {
			Product p = new Product();

			p.setMainProduct(true);
			p.setCode(c.split(",")[0]);
			p.setContractName(c.split(",")[1]);

			p.setMaxOrderNum((int) (Double.parseDouble(c.split(",")[2])));
			if (c.split(",")[3].length() > 3) {
				p.setCallOption(c.split(",")[3].split("#")[0]);
				p.setPutOption(c.split(",")[3].split("#")[1]);
			}
			p.setHighestPrice(Double.parseDouble(c.split(",")[4]));
			p.setLowestPrice(Double.parseDouble(c.split(",")[5]));

			File f = new File("d:\\kline2\\" + p.getCode() + ".high");
			if (f.exists()) {
				p.setHighestPrice(
						Double.parseDouble(JavaFile.readfileToString("d:\\kline2\\" + p.getCode() + ".high")));
			}

			f = new File("d:\\kline2\\" + p.getCode() + ".low");
			if (f.exists()) {
				p.setLowestPrice(Double.parseDouble(JavaFile.readfileToString("d:\\kline2\\" + p.getCode() + ".low")));
			}

			p.setAtr(Double.parseDouble(c.split(",")[6]));
			if (unitMap.get(p.getContractName()) != null) {
				p.setUnit(unitMap.get(p.getContractName()));
				p.setMinStep(minStepMap.get(p.getContractName()));
			}
			p.setMa20(Double.parseDouble(c.split(",")[7]));

			productMap.put(c.split(",")[0], p);
		}

		OptionArbitrage s = new OptionArbitrage();
		s.tickThread.start();
		s.tradeThread.start();

		Timer timer1 = new Timer();
		timer1.schedule(new TimerTask() {
			public void run() {
				started = true;
			}
		}, 60 * 1000);

		Timer timer2 = new Timer();
		timer2.schedule(new TimerTask() {
			public void run() {
				while (true) {
					List<Product> plist = new ArrayList<Product>();
					for (String k : productMap.keySet()) {
						Product p = productMap.get(k);
						if (p.isMainProduct() && p.getLastPrice() > 0) {
							if (p.getOwnPosition() > 0) {
								if (Math.abs(p.getHighestPrice() - p.getLastPrice()) > Math
										.abs(p.getLowestPrice() - p.getLastPrice())) {
									p.setDistance(Math.abs(p.getLowestPrice() - p.getLastPrice()) / p.getAtr());
								} else {
									p.setDistance(Math.abs(p.getHighestPrice() - p.getLastPrice()) / p.getAtr());
								}

								plist.add(p);
							}

						}
					}

					plist.add(new Product());
					for (String k : productMap.keySet()) {
						Product p = productMap.get(k);
						if (p.isMainProduct() && p.getLastPrice() > 0) {
							if (p.getOwnPosition() == 0) {
								if (Math.abs(p.getHighestPrice() - p.getLastPrice()) > Math
										.abs(p.getLowestPrice() - p.getLastPrice())) {
									p.setDistance(Math.abs(p.getLowestPrice() - p.getLastPrice()) / p.getAtr());
								} else {
									p.setDistance(Math.abs(p.getHighestPrice() - p.getLastPrice()) / p.getAtr());
								}

								if (p.getDistance() < 0.4) {
									plist.add(p);
								}

							}

						}
					}

					ObjectMapper mapper = new ObjectMapper();

					// 将 ArrayList 转换为 JSON 字符串
					String json;
					try {
						json = mapper.writeValueAsString(plist);
//						System.out.println(json);
						Handler.sendMessage(json);
					} catch (JsonProcessingException e) {
						e.printStackTrace();
					}

					try {
						Thread.sleep(60 * 1000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}

			}
		}, 60 * 1000);

		new Websocket().service(5001);
	}

	private static String convertToJson(List<Product> data) {
		StringBuilder json = new StringBuilder("[");
		for (Product p : data) {
			json.append(p.toString()).append(",");
		}
		if (!data.isEmpty()) {
			json.deleteCharAt(json.length() - 1); // 移除最后一个逗号
		}
		json.append("]");
		return json.toString();
	}

	public static String connection1[] = { "i", "j", "jm" };
	public static String connection2[] = { "T", "TF", "TS", "TL" };
	public static String connection3[] = { "rb", "ss", "i", "hc" };
	public static String connection4[] = { "ao", "al" };
	public static String connection5[] = { "CF", "CY" };
	public static String connection6[] = { "IF", "IH", "IC", "IM" };
	public static String connection7[] = { "RM", "m" };
	public static String connection8[] = { "br", "ru", "nr" };
	public static String connection9[] = { "y", "p", "OI" };
	public static String connection10[] = { "TA", "PX", "PR" };
	public static String connection11[] = { "sc", "fu", "lu" };
	public static String connection12[] = { "FG", "SA" };
	public static String connection13[] = { "c", "cs" };
	public static String connection14[] = { "a", "b", "m", "y" };

	public static List<String[]> relationProductList = new ArrayList<String[]>();
	public static HashMap<String, Double> unitMap = new HashMap<String, Double>();
	public static HashMap<String, Double> minStepMap = new HashMap<String, Double>();
	static {

		relationProductList.add(connection1);
		relationProductList.add(connection2);
		relationProductList.add(connection3);
		relationProductList.add(connection4);
		relationProductList.add(connection5);
		relationProductList.add(connection6);
		relationProductList.add(connection7);
		relationProductList.add(connection8);
		relationProductList.add(connection9);
		relationProductList.add(connection10);
		relationProductList.add(connection11);
		relationProductList.add(connection12);
		relationProductList.add(connection13);
		relationProductList.add(connection14);
		unitMap.put("pp", 5.0);
		minStepMap.put("pp", 1.0);
		unitMap.put("PR", 15.0);
		minStepMap.put("PR", 2.0);
		unitMap.put("PX", 5.0);
		minStepMap.put("PX", 2.0);
		unitMap.put("lu", 10.0);
		minStepMap.put("lu", 1.0);
		unitMap.put("MA", 10.0);
		minStepMap.put("MA", 1.0);
		unitMap.put("IC", 200.0);
		minStepMap.put("IC", 0.2);
		unitMap.put("eb", 5.0);
		minStepMap.put("eb", 1.0);
		unitMap.put("IF", 300.0);
		minStepMap.put("IF", 0.2);
		unitMap.put("UR", 20.0);
		minStepMap.put("UR", 1.0);
		unitMap.put("ec", 50.0);
		minStepMap.put("ec", 0.1);
		unitMap.put("IH", 300.0);
		minStepMap.put("IH", 0.2);
		unitMap.put("eg", 10.0);
		minStepMap.put("eg", 1.0);
		unitMap.put("IM", 200.0);
		minStepMap.put("IM", 0.2);
		unitMap.put("ag", 15.0);
		minStepMap.put("ag", 1.0);
		unitMap.put("al", 5.0);
		minStepMap.put("al", 5.0);
		unitMap.put("ao", 20.0);
		minStepMap.put("ao", 1.0);
		unitMap.put("PL", 20.0);
		minStepMap.put("PL", 1.0);
		unitMap.put("AP", 10.0);
		minStepMap.put("AP", 1.0);
		unitMap.put("rb", 10.0);
		minStepMap.put("rb", 1.0);
		unitMap.put("au", 1000.0);
		minStepMap.put("au", 0.02);
		unitMap.put("zn", 5.0);
		minStepMap.put("zn", 5.0);
		unitMap.put("jd", 10.0);
		minStepMap.put("jd", 1.0);
		unitMap.put("ni", 1.0);
		minStepMap.put("ni", 10.0);
		unitMap.put("RM", 10.0);
		minStepMap.put("RM", 1.0);
		unitMap.put("fb", 10.0);
		minStepMap.put("fb", 0.5);
		unitMap.put("bc", 5.0);
		minStepMap.put("bc", 10.0);
		unitMap.put("FG", 20.0);
		minStepMap.put("FG", 1.0);
		unitMap.put("RS", 10.0);
		minStepMap.put("RS", 1.0);
		unitMap.put("jm", 60.0);
		minStepMap.put("jm", 0.5);
		unitMap.put("ru", 10.0);
		minStepMap.put("ru", 5.0);
		unitMap.put("nr", 10.0);
		minStepMap.put("nr", 5.0);
		unitMap.put("SA", 20.0);
		minStepMap.put("SA", 1.0);
		unitMap.put("fu", 10.0);
		minStepMap.put("fu", 1.0);
		unitMap.put("br", 5.0);
		minStepMap.put("br", 5.0);
		unitMap.put("sc", 1000.0);
		minStepMap.put("sc", 0.1);
		unitMap.put("bu", 10.0);
		minStepMap.put("bu", 1.0);
		unitMap.put("SF", 5.0);
		minStepMap.put("SF", 2.0);
		unitMap.put("T", 10000.0);
		minStepMap.put("T", 0.005);
		unitMap.put("SH", 30.0);
		minStepMap.put("SH", 1.0);
		unitMap.put("si", 5.0);
		minStepMap.put("si", 5.0);
		unitMap.put("OI", 10.0);
		minStepMap.put("OI", 1.0);
		unitMap.put("SM", 5.0);
		minStepMap.put("SM", 2.0);
		unitMap.put("sn", 1.0);
		minStepMap.put("sn", 10.0);
		unitMap.put("sp", 10.0);
		minStepMap.put("sp", 2.0);
		unitMap.put("SR", 10.0);
		minStepMap.put("SR", 1.0);
		unitMap.put("ss", 5.0);
		minStepMap.put("ss", 5.0);
		unitMap.put("a", 10.0);
		minStepMap.put("a", 1.0);
		unitMap.put("b", 10.0);
		minStepMap.put("b", 1.0);
		unitMap.put("c", 10.0);
		minStepMap.put("c", 1.0);
		unitMap.put("CF", 5.0);
		minStepMap.put("CF", 5.0);
		unitMap.put("CJ", 5.0);
		minStepMap.put("CJ", 5.0);
		minStepMap.put("ad", 5.0);
		unitMap.put("ad", 10.0);
		minStepMap.put("ps", 5.0);
		unitMap.put("ps", 3.0);
		minStepMap.put("bz", 1.0);
		unitMap.put("bz", 30.0);
		unitMap.put("i", 100.0);
		minStepMap.put("i", 0.5);
		unitMap.put("j", 100.0);
		minStepMap.put("j", 0.5);
		unitMap.put("l", 5.0);
		minStepMap.put("l", 1.0);
		unitMap.put("m", 10.0);
		minStepMap.put("m", 1.0);
		unitMap.put("TA", 5.0);
		minStepMap.put("TA", 2.0);
		unitMap.put("cs", 10.0);
		minStepMap.put("cs", 1.0);
		unitMap.put("p", 10.0);
		minStepMap.put("p", 2.0);
		unitMap.put("cu", 5.0);
		minStepMap.put("cu", 10.0);
		unitMap.put("pb", 5.0);
		minStepMap.put("pb", 5.0);
		unitMap.put("TF", 10000.0);
		minStepMap.put("TF", 0.005);
		unitMap.put("CY", 5.0);
		minStepMap.put("CY", 5.0);
		unitMap.put("PF", 5.0);
		minStepMap.put("PF", 2.0);
		unitMap.put("v", 5.0);
		minStepMap.put("v", 1.0);
		unitMap.put("lc", 1.0);
		minStepMap.put("lc", 50.0);
		unitMap.put("pg", 20.0);
		minStepMap.put("pg", 1.0);
		unitMap.put("TL", 10000.0);
		minStepMap.put("TL", 0.01);
		unitMap.put("y", 10.0);
		minStepMap.put("y", 2.0);
		unitMap.put("hc", 10.0);
		minStepMap.put("hc", 1.0);
		unitMap.put("PK", 5.0);
		minStepMap.put("PK", 2.0);
		unitMap.put("lh", 16.0);
		minStepMap.put("lh", 5.0);
		unitMap.put("TS", 20000.0);
		minStepMap.put("TS", 0.002);
		unitMap.put("lg", 90.0);
		minStepMap.put("lg", 0.5);
	}
}

//a2211,黄豆1,sell,2,1,10,s1,8
//al2210,铝,buy,2,5,5,s1,5
//au2212,黄金,buy,1,0.02,1000,s1,5
//bu2212,沥青,buy,2,1,10,s1,7
//c2301,玉米,buy,4,1,10,s1,3
//CF301,棉花,buy,1,5,5,s1,4
//m2301,豆粕,sell,1,1,10,s1,4
//cu2210,铜,buy,1,10,5,s1,5
//ni2210,镍,buy,1,10,1,s1,1
//rb2301,螺纹钢,buy,2,1,10,s1,6
//ru2301,橡胶,buy,1,5,10,s1,2
//sp2301,纸浆,buy,1,2,10,s1,8
//SR301,白糖,buy,1,1,10,s1,4
//zn2210,锌,buy,1,5,5,s1,4
//sn2210,锡,buy,1,10,1,s1,1
//pb2210,铅,buy,1,5,5,s1,2
//ag2212,白银,buy,2,1,15,s1,2
//y2301,豆油,buy,1,2,10,s1,7
//p2301,棕榈油,buy,1,2,10,s1,10

//jd2301,鸡蛋,buy,2,1,10,s1,5
//AP210,苹果,buy,1,1,10,s1,9